<?php
/**
 * Created by PhpStorm.
 * User: yangfan
 * Date: 2019/11/28
 * Time: 5:07 PM
 */

namespace App\BO\Order\OrderRollback;

use App\Entities\OrderEntity;
use App\ServicesNew\UserBalanceService;
use Illuminate\Support\Facades\Log;

class BalanceOrderRollback implements IOrderRollback
{
    public static function handle(OrderEntity $order, \Closure $next)
    {
        // 2. 回退余额
        if ($transactionRecordId = $order->getTransactionRecordId()) {
            /** * @var UserBalanceService $balanceService */
            $balanceService = app(UserBalanceService::class);
            $balanceService->orderRollback($order);
            Log::info('订单' . $order->getId() . '：余额回退成功');
        } else {
            Log::info('订单' . $order->getId() . '：末使用余额，不用回退');
        }

        return $next($order);
    }
}
